package com.yidui.core.uikit.emoji.utils

import android.text.TextUtils
import android.view.View
import android.widget.Toast

/**
 * Created by saxer on 2017/7/26.
 */
abstract class NoDoubleClickListener : View.OnClickListener {
    private var MIN_CLICK_DELAY_TIME: Long = 0
    private var lastClickTime: Long = 0
    private var toastDesc: String? = null

    constructor(minClickDelayTime: Long? = 1000) {
        if (minClickDelayTime != null) {
            MIN_CLICK_DELAY_TIME = minClickDelayTime
        }
    }

    constructor(minClickDelayTime: Long? = 1000, toastDesc: String?) {
        if (minClickDelayTime != null) {
            MIN_CLICK_DELAY_TIME = minClickDelayTime
        }
        this.toastDesc = toastDesc
    }

    override fun onClick(v: View) {
        val currentTime = System.currentTimeMillis()
        if (currentTime - lastClickTime > MIN_CLICK_DELAY_TIME) {
            lastClickTime = currentTime
            onNoDoubleClick(v)
        } else {
            if (!TextUtils.isEmpty(toastDesc)) {
//                ToastUtil.show(toastDesc)
                Toast.makeText(v.context, toastDesc, Toast.LENGTH_SHORT).show()
            }
        }
    }

    abstract fun onNoDoubleClick(v: View?)
}